public class race {
    private int toristDistance;
    private int rabitDistance;

    class Torist extends Thread{
        @Override
        public void run(){
            for (int i=1;i<=800;i++){
                if (rabitDistance==800){
                    System.out.println("兔子赢得了比赛，此时乌龟才跑了"+toristDistance+"米");
                    break;
                }else{
                    toristDistance+=1;
                    if (toristDistance%100==0){
                        try {
                            if (rabitDistance==700){
                                System.out.println("乌龟跑了"+toristDistance+"米,此时兔子在睡觉");
                            }else {
                                System.out.println("乌龟跑了"+toristDistance+"米，此时兔子跑过段距离"+rabitDistance);
                            }
                            Thread.sleep(1500);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }

    class Rabit extends Thread{
        @Override
        public void run(){
            for (int i=1;i<=800;i++){
                if (toristDistance==800){
                    System.out.println("乌龟赢得了比赛，此时兔子才跑了"+rabitDistance+"米");
                    break;
                }else{
                    rabitDistance+=5;
                    if (rabitDistance%100==0){
                        try {
                            System.out.println("兔子跑了"+rabitDistance+"米，乌龟跑过了"+toristDistance);
                            if (rabitDistance==700){
                                System.out.println("兔子觉得自己怎么都能赢得比赛，所以选择睡一会");
                                Thread.sleep(10000);
                            }
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }


    public static void main(String[] args) {
        race outer=new race();

        Rabit rabit=outer.new Rabit();
       Torist torist=outer.new Torist();

       rabit.start();
       torist.start();

    }
}
